<!DOCTYPE html>
<html lang="zh"><head>
<th:block th:include="include :: header('验证域名所有权')" />
<th:block th:include="include :: jquery-smartwizard-css" />
<style type="text/css">
/* 如果要让工具栏固定在页面底部,使用下面的样式,不需要的可以注释 */
.sw>.toolbar-bottom{
	z-index: 100;
    bottom: 0px;
    left: 0;
    width: 100%;
    position: fixed;
    text-align: right;
    background: #fff;
    box-shadow: 0 -2px 6px 1px hsla(223,8%,83%,.5);
    border-top: 1px solid #e3e4e8;
}
/* 如果设置了是否自动调节高度为false,需要加滚动条 */
.sw>.tab-content{
	overflow-x: hidden;
    overflow-y: auto;
}
/* 解决工具栏无法固定底部的问题（如果页面没有animated类可以不写这部分代码） */
.animated {
    animation-fill-mode: none;
    -webkit-animation-fill-mode: none;
    -moz-animation-fill-mode: none;
    -o-animation-fill-mode: none;
}
</style>
</head>
<body class="gray-bg" style="padding: 15px;">
	<div th:if="${authJson == null}">
		<h3>[[${msg}]]</h3>
	</div>
	<div class="tab-pane" th:if="${authJson != null}">
		<div class="ibox float-e-margins">
			<div class="ibox-title" style="display: flex; align-items: center;">
				<h3>dns-01【验证方式】</h3>
			</div>
			<div class="ibox-content">
				<p>请配置以下DNS解析记录(配置成功后，<text style="color: red; font-weight: bold;font-size: 18px;">请勿删除记录</text> )不删除解析记录，自动续签就可以免验证。</p>
				<div class="table-responsive">
					<table class="table table-bordered table-striped">
						<thead>
							<tr>
								<th>证书域名</th>
								<th>主机记录</th>
								<th>记录类型</th>
								<th>记录值</th>
							</tr>
						</thead>
						<tbody>
							<tr>
								<td>[[${sslApply.certificateDomain}]]</td>
								<td c>
									[[${authJson.domainName}]]
									<i onclick="copyToClipboard('domainName')" class="fa fa fa-clone"></i>
								</td>
								<td>TXT</td>
								<td style="color: #5B89FE;">
									[[${authJson.keyAuthorization}]]
									<i onclick="copyToClipboard('key')" class="fa fa fa-clone"></i>
								</td>
							</tr>
						</tbody>
					</table>
				</div>
			</div>
		</div>
<!--		<button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>开始验证</button>&nbsp;-->
	</div>
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: jquery-smartwizard-js" />
	<script>
		function copyToClipboard(text) {
			if(text === 'key'){
				text = '[[${authJson.keyAuthorization}]]';
			}else if(text === 'domainName'){
				text = '[[${authJson.domainName}]]';
			}
			var textarea = document.createElement('textarea');
			textarea.style.position = 'fixed';
			textarea.style.opacity = 0;
			textarea.value = text;
			document.body.appendChild(textarea);
			textarea.select();
			document.execCommand('copy');
			document.body.removeChild(textarea);
			$.modal.msgSuccess("复制成功！");
		}

		function submitHandler (){
			$.modal.confirm("您确定要已完成配置开始验证吗？", function (confirm){
				if(confirm){
					var id = [[${sslApply.id}]];
					$.operate.get(ctx + "SSL/apply/authz/" + id, function(res){
						if(res.code === 0){
							//直接执行签发证书的方法
							setTimeout(function (){
								$.operate.post(ctx + "SSL/apply/downCertificate/"+id, null, function (res1){
									if(res1.code === 0){
										$.modal.msgWarning('证书签发中！');
										$.operate.successCallback(res1);
									}else{
										$.modal.msgError(res1.msg);
									}
								}, "正在申请签发证书,请稍后...")
							},1000)
						}else{
							if(res.status === 'invalid'){
								$.modal.msgError('验证挑战已失效！');
							}else if(res.status === 'pending'){
								$.modal.msgError('验证挑战失败，请重试！');
							}else{
								$.modal.msgError('验证失败，请重新点击验证！');
							}
						}
					}, "签名验证中,请稍后...");
				}
			});
		}
	</script>
</body>
</html>
